package com.xsoft.action;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import com.xsoft.formBean.LoginForm;
import com.xsoft.formBean.RegisterForm;

import struts.base.BaseActionForm;
import struts.annotation.ActionMapping;
import struts.annotation.FormBean;
import struts.base.BaseAction;

@ActionMapping(name="register", type="com.xsoft.action.RegisterAction", path="/register", success="/view/registerSuccess.jsp", fail="/view/registerFail.jsp")
public class RegisterAction implements BaseAction {

	/**
	 * 用户注册业务逻辑
	 * 返回model view
	 * 
	 */
	@Override
	public String execute(HttpServletRequest request, BaseActionForm form, Map<String, String> actionForward) {
		String forward_name="";
		String forward_url="";
		RegisterForm registerForm=(RegisterForm)form;
		String username = registerForm.getUsername();
		String password1 = registerForm.getPassword1();
		String password2 = registerForm.getPassword2();
		String email = registerForm.getEmail();
		if(password1.equals(password2)){
			forward_name="success";
			forward_url=actionForward.get(forward_name); // /view/registerSuccess.jsp
			request.setAttribute("username", username);
			request.setAttribute("email", email);
		}else{
			forward_name="fail";
			forward_url=actionForward.get(forward_name); // /view/registerFail.jsp
		}
		return forward_url;
	}
}
